package org.linlinjava.litemall.admin.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @Author: Daisen.Z
 * @Date: 2021/6/4 10:47
 * @Version: 1.0
 * @Description:
 */
public class AdminStringUtil {

    public static String get32UUID(){
        return UUID.randomUUID().toString().replace("-", "");
    }

    // 设置对象的所需值
    public static void setAdminInsertInfo(Object o){
        try {
            Class<?> clazz = o.getClass();
            Method setAdminName = clazz.getMethod("setAdminName", String.class);
            Method setInsertTime = clazz.getMethod("setInsertTime", LocalDateTime.class);
            setAdminName.invoke(o,AdminCheck.getUserName());
            setInsertTime.invoke(o,LocalDateTime.now());
            setAdminUpdateInfo(o);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    // 设置对象的所需值
    public static void setAdminUpdateInfo(Object o){
        try {
            Class<?> clazz = o.getClass();
            Method setUpdateAdminName = clazz.getMethod("setUpdateAdminName", String.class);
            Method setUpdateTime = clazz.getMethod("setUpdateTime", LocalDateTime.class);
            setUpdateAdminName.invoke(o,AdminCheck.getUserName());
            setUpdateTime.invoke(o,LocalDateTime.now());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

}
